package com.easylinkin.linkappapi.childinspection.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.easylinkin.linkappapi.childinspection.entity.InspectionQrCodeEntity;
import com.easylinkin.linkappapi.childinspection.service.InspectionQrCodeService;
import com.easylinkin.linkappapi.childinspection.vo.BaseVo;
import com.easylinkin.linkappapi.childinspection.vo.InspectionQrCodeVo;
import com.easylinkin.linkappapi.childinspection.vo.RelationVo;
import com.easylinkin.linkappapi.common.model.RequestModel;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author linWenLe
 * @Date: 2024/3/27
 * @Description: 巡检点管理
 */
@RestController
@RequestMapping("/inspectionQrCode")
public class InspectionQrCodeController extends ApiController {

    @Resource
    private InspectionQrCodeService inspectionQrCodeService;

    /***
     * 巡检点列表
     * @return
     */
    @RequestMapping("getList")
    public RestMessage getList(@RequestBody RequestModel<InspectionQrCodeVo> restPage) {
        return  RestBuilders.successBuilder(inspectionQrCodeService.getList(restPage)).build();
    }

    /***
     * 生成巡检点编号
     * @return
     */
    @RequestMapping("createCode")
    public RestMessage createCode() {
        return  RestBuilders.successBuilder(inspectionQrCodeService.createCode()).build();
    }

    /***
     * 新增巡检点
     * @return
     */
    @RequestMapping("insert")
    public RestMessage insert(@RequestBody InspectionQrCodeVo entity) {
        inspectionQrCodeService.insert(entity);
        return  RestBuilders.successBuilder().message("新增成功").build();
    }

    /***
     * 修改巡检点
     * @return
     */
    @RequestMapping("update")
    public RestMessage update(@RequestBody InspectionQrCodeEntity entity) {
        inspectionQrCodeService.update(entity);
        return  RestBuilders.successBuilder().message("修改成功").build();
    }

    /***
     * 查询详情
     * @return
     */
    @RequestMapping("getQrCodeInfo")
    public RestMessage getQrCodeInfo(String id) {
        return  RestBuilders.successBuilder(inspectionQrCodeService.getQrCodeInfo(id)).build();
    }

    /***
     * 删除巡检点
     * @return
     */
    @RequestMapping("delete")
    public RestMessage delete(String id) {
        inspectionQrCodeService.delete(id);
        return  RestBuilders.successBuilder().message("删除成功").build();
    }

    /***
     * 二维码使用记录
     * @return
     */
    @RequestMapping("getUseList")
    public RestMessage getUseList(@RequestBody RequestModel<BaseVo> restPage) {
        return  RestBuilders.successBuilder(inspectionQrCodeService.getUseList(restPage)).build();
    }

    /***
     * 二维码关联巡检点
     * @return
     */
    @RequestMapping("relationPoint")
    @Transactional
    public RestMessage relationPoint(@RequestBody RelationVo relationVo) {
        inspectionQrCodeService.relationPoint(relationVo);
        return  RestBuilders.successBuilder().message("关联成功").build();
    }

    /***
     * 二维码解除关联
     * @return
     */
    @RequestMapping("relieve")
    @Transactional
    public RestMessage relieve(@RequestBody RelationVo relationVo) {
        inspectionQrCodeService.relieve(relationVo);
        return  RestBuilders.successBuilder().message("解除关联成功").build();
    }
}
